#include <iostream>
using namespace std;

const int N = 1e5 + 5;
int arr[N];
int n;

bool f(int energy, int max)
{
    for (int i = 1; i <= n; i++)
    {
        if (energy >= arr[i])
            energy += energy - arr[i];
        else
            energy -= arr[i] - energy;

        if (energy > max)
            return true;
        if (energy < 0)
            return false;
    }
    return true;
}

int main() {
    cin >> n;
    int max = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &arr[i]);
        if (arr[i] > max)  max = arr[i];
    }

    int l = 0;
    int r = max;
    int m = 0;
    int ans = -1;

    while (l <= r) {
        m = l + ((r - l) >> 1);
        if (f(m, max))
        {
            ans = m;
            r = m - 1;
        }
        else {
            l = m + 1;
        }
    }
    cout << ans << endl;
    return 0;
}
